﻿#include <QApplication>
#include <QQmlApplicationEngine>
#include <logfile.h>
#include <QtQml>
#include "qmlobjecttest.h"
#include "qdebug2logcat.h"

#include <QDebug>
#include <QScreen>
#include <QFont>
#include <QtGui/QGuiApplication>
#include <QQuickView>

#include "mainwindow.h"
#include "upmainwindow.h"

#ifdef ANDROID
#include "mycommon.h"
#include <QAndroidJniEnvironment>
#include <QAndroidJniObject>
#endif


int main(int argc, char *argv[])
{

#ifdef ANDROID
    installLogcatMessageHandler("yourLogTag");
#else

    //打开日志文件，以文本写入方式
    logFile::g_log_fp = fopen("my.log", "wt");
    //程序退出时关闭日志文件
    atexit(logFile::closeLogFile);

    //使用我的日志类处理qt日志
    qInstallMessageHandler(logFile::myMessageOutput);

#endif

//    QApplication app(argc, argv);
    QGuiApplication app(argc, argv);

    QScreen *screen = app.primaryScreen();
    QFont font = app.font();
    int pixelSize = (font.pointSize()*screen->logicalDotsPerInch()) / 72;

    //    font.setPointSize(100);
    //    app.setFont(font);

    qmlRegisterType<qmlObjectTest>("QmlObjectTest", 1, 0, "QmlObjectTest");

    qmlRegisterType<MainWindow>("MainWindow", 1, 0, "MainWindow");
    qmlRegisterType<UpMainWindow>("UpMainWindow", 1, 0, "UpMainWindow");

#ifdef ANDROID
    qmlRegisterType<MyCommon>("MyCommon", 1, 0, "MyCommon");


#endif

    //    QQmlApplicationEngine engine;


    QQuickView view;

#ifdef ANDROID
    //    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    view.setSource(QUrl("qrc:/main.qml"));

#else
    view.setSource(QUrl("qrc:/main.qml"));
    //    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
#endif
    view.setTitle(QStringLiteral("opengl and qml"));
    view.setWidth(800);
    view.setHeight(600);
    view.show();

    return app.exec();
}

